﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UserData
{
    public partial class NGCount_Control : UserControl
    {
        public NGCount_Control()
        {
            InitializeComponent();
        }

        private void NGCount_Control_Load(object sender, EventArgs e)
        {
            NGCountMgr.GetInstance().OnTestReflushNG += OnReslushNGCount;
            table_NGCount.RowStyles.Clear();
            table_NGCount.ColumnStyles.Clear();
            table_NGCount.Controls.Clear();
            table_NGCount.RowCount = 2;
            int n_Column= (int)NGCountMgr.GetInstance().NGTatal.Count;
            table_NGCount.ColumnCount = n_Column;
            for (int i = 0; i < 2; i++)
            {
                table_NGCount.RowStyles.Add(new RowStyle(SizeType.Percent, (float)1.0 / 2));
                for (int j = 0; j < n_Column; j++)
                {
                    table_NGCount.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (float)1.0 / n_Column));
                }
            }
            int n_Index = 0;
            foreach (var item in NGCountMgr.GetInstance().NGTatal)
            {
                Label lable = new Label();
                lable.Dock = DockStyle.Fill;
                lable.BackColor = Color.Red;
                lable.Text = item.Key;
                table_NGCount.Controls.Add(lable, 0, n_Index);
                n_Index++;
            }
            n_Index = 0;
            foreach (var item in NGCountMgr.GetInstance().NGTatal)
            {
                Label lable = new Label();
                lable.Dock = DockStyle.Fill;
                lable.BackColor = Color.Red;
                lable.Text = item.Value.ToString();
                table_NGCount.Controls.Add(lable, 1, n_Index);
                n_Index++;
            }

        }

        public void OnReslushNGCount()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new Action(() => OnReslushNGCount()));
            }
            else
            {
                int n_Index = 0;
                foreach (var item in NGCountMgr.GetInstance().NGTatal)
                {
                    ((Label)table_NGCount.Controls[n_Index * 2 + 1]).Text = item.Value.ToString();
                    n_Index++;
                }
            }


        }

        private void 清除数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NGCountMgr.GetInstance().ClearNGCount();
        }
    }
}
